package net.lastcoder.ifserver.packet;

import net.lastcoder.ifserver.module.BaseModule;
import net.lastcoder.ifserver.nio.UnauthorizedException;
import net.lastcoder.ifserver.session.Session;

/**
 *
 * auth: WenYF
 * date: 2016/9/29
 */
public abstract class EventHandler extends BaseModule {
    private short type;

    public EventHandler(String name, short type) {
        super(name);
        this.type = type;
    }

    public short getEventType() {
        return type;
    }
    @Override
    public void init() {

    }

    @Override
    public void destroy() {}

    /**
     *
     * @param packet
     * @return false让系统继续处理,true不在继续处理
     * @throws UnauthorizedException
     */
    public abstract boolean handle(Session from, Event packet) throws UnauthorizedException;

    @Override
    public String toString() {
        return "EventHandler{" +
                "name=" + getName() +
                "type=" + type +
                '}';
    }
}
